<template>
  <el-dialog
    title="选择地址"
    :visible.sync="dialogVisible"
    append-to-body
    top="10%"
    width="98%">
    <div class="address-list">
      <address-item :call-back="confirm" :class="{curr:address.id===addressItem.id}" v-for="(addressItem,index) in addressList" :key="index" :address-data="addressItem" :show-type="2"/>
      <div class="c"></div>
    </div>
<!--    <div slot="footer" class="dialog-footer">-->
<!--      <el-button type="primary" @click="confirm">确认选择</el-button>-->
<!--    </div>-->
  </el-dialog>

</template>

<script>
import AddressItem from './AddressItem'
export default {
  name: 'ChooseAddressDialog',
  components: {AddressItem},
  data: function () {
    return {
      callback:null,
      dialogVisible:false,
      addressList:[],
      address:{},
    }
  },
  mounted () {
    let $this = this
    $this.bus.$on('ChooseAddressDialogCallBus', function (address,callback) {
      $this.dialogVisible = true
      $this.callback=callback
      if (address){
        $this.address=address && address.id?address:{}
      }
      $this.getAddressList()
      $this.$forceUpdate()
    })
  },
  methods: {
    confirm:function (addressItem) {
      if (typeof this.callback==='function'){
        this.callback(addressItem)
        this.dialogVisible = false
        this.$forceUpdate()
      }
    },
    getAddressList: function () {
      let $this = this
      $this.MyRequest(this.ApiDoNameShop + 'ShopAddress/getList', {}, function (data) {
        $this.addressList = data && data.length>0?data:[]
        $this.dialogVisible = true
        $this.$forceUpdate()
      }, function () {
        $this.$message.success('操作失败，请重试')
        $this.currLoading = false
        $this.$forceUpdate()
      })
    }
  }
}
</script>

<style scoped>

</style>
